package com.zhangh.summer.admin.controller.menu;

import com.zhangh.summer.admin.biz.menu.MenuBiz;
import com.zhangh.summer.admin.model.bo.DataBO;
import com.zhangh.summer.admin.model.bo.MenuBO;
import com.zhangh.summer.admin.model.bo.MenuQuery;
import com.zhangh.summer.admin.support.base.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author: zhanghui  zhanghlucky@163.com
 * @create: 2021-10-08 21:50
 **/
@RestController
@RequestMapping(value = "/menu",method = RequestMethod.POST)
public class MenuController {
    @Autowired
    private MenuBiz menuBiz;


    @RequestMapping("/dataList")
    public String dataList(@RequestBody MenuQuery query) {
        List<MenuBO> list=this.menuBiz.getMenuList(query);
        return new JsonResponse().toJson(list);
    }

    @RequestMapping("/getMenu/{id}")
    public String getMenu(@PathVariable Long id) {
        MenuBO menuBO=this.menuBiz.getMenuBO(id);
        return new JsonResponse().toJson(menuBO);
    }

    @RequestMapping("/save")
    public String save(@RequestBody MenuBO menuBO) {
        long c1=this.menuBiz.saveMenu(menuBO);
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/update")
    public String update(@RequestBody MenuBO menuBO) {
        int c1=this.menuBiz.updateMenu(menuBO);
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/delete")
    public String delete(@RequestBody DataBO dataBO) {
        int c1=this.menuBiz.deleteMenu(dataBO.getId());
        return new JsonResponse().toJson(c1);
    }

    @RequestMapping("/updateSort")
    public String updateSort(@RequestBody List<MenuBO> menuBOList) {
        this.menuBiz.menuSort(menuBOList);
        return new JsonResponse().toJson();
    }

    @RequestMapping("/setHome")
    public String setHome(@RequestBody DataBO dataBO) {
        int c1=this.menuBiz.setHome(dataBO.getId());
        return new JsonResponse().toJson(c1);
    }

}
